package cn.huyanbing.visual.spring.research.drools;

import cn.huyanbing.visual.spring.research.drools.bean.Politician;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;


/**
 * @BelongProject middleware
 * @BelongPackage cn.huyanbing.visual.spring.research.drools
 * @Description  规则引擎 Drools 与SpringBoot 的使用
 *    https://github.com/MyHerux/drools-springboot?tab=readme-ov-file
 *
 *    /resources/META-INF/kmodule.xml
 *    使用kmodule的方式调用drools
 * @ClassName HonestPoliticianExample
 * @Author huyangbing
 * @Date 2025/1/22 14:00
 * @Version 1.0.0
 */
public class HonestPoliticianExample {
    public HonestPoliticianExample() {
    }


    public static void main(final String[] args) {
        KieContainer kc = KieServices.Factory.get().getKieClasspathContainer();
        System.out.println(kc.verify().getMessages().toString());
        execute(kc);
    }

    private static void execute(KieContainer kc) {
        KieSession ksession = kc.newKieSession("HonestPoliticianKS");
        Politician p1 = new Politician("President of Umpa Lumpa", true);
        Politician p2 = new Politician("Prime Minster of Cheeseland", true);
        Politician p3 = new Politician("Tsar of Pringapopaloo", true);
        Politician p4 = new Politician("Omnipotence Om", true);
        ksession.insert(p1);
        ksession.insert(p2);
        ksession.insert(p3);
        ksession.insert(p4);
        ksession.fireAllRules();
        ksession.dispose();
    }
}
